package com.huadi.firematerialident.dao;

import com.huadi.firematerialident.po.Appraisal;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class AppraisalDaoImpl implements AppraisalDao{

    @Autowired
    JdbcTemplate jdbcTemplate;

    @Override
    public int addAppraisal(Appraisal appraisal) {

        String sql="insert into appraisal values(?,?,?,now(),?,'否','否',1,now())";
        return jdbcTemplate.update(sql,
                appraisal.getApsID(),
                appraisal.getAppID(),
                appraisal.getIdentID(),
                appraisal.getApsConclusion());
    }

    @Override
    public int deleteAppraisalByID(String ApsID) {
        String sql="update appraisal set LogicalAddDel=0,LastModification=now() where ApsID=?";
        return jdbcTemplate.update(sql,ApsID);
    }

    @Override
    public int updateAppraisal(Appraisal appraisal) {
        String sql="update appraisal set AppID=?,IdentID=?,ApsConclusion=?,RevStatus=?,ArchivingStatus=?,LastModification=now() where ApsID=?";
        System.out.println("gengxing");
        System.out.println(appraisal.getRevStatus());
        System.out.println(appraisal.getApsID());
        return jdbcTemplate.update(sql,
                appraisal.getAppID(),
                appraisal.getIdentID(),
                appraisal.getApsConclusion(),
                appraisal.getRevStatus(),
                appraisal.getArchivingStatus(),
                appraisal.getApsID());
    }

    @Override
    public List<Map<String,Object>> selectAppraisalByID(String ApsID) {
        String sql="select * from appraisal where ApsID=?";
        return jdbcTemplate.queryForList(sql,ApsID);
    }

    @Override
    public List<Map<String,Object>> getAllAppraisal() {
        String sql="select * from appraisal";
        return jdbcTemplate.queryForList(sql);
    }

    @Override
    public List<Map<String,Object>> selectAppraisalByID1(String AppID) {
        String sql="select * from appraisal where AppID=?";
        return jdbcTemplate.queryForList(sql,AppID);
    }


}
